package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;

@Mapper
public interface OrderMapper {
    /**
     * 插入订单数据
     * @param order
     */
    void insert(Orders order);


    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    /**
     * 取消订单
     * @param orders
     */
    void update(Orders orders);

    /**
     * 分页查询历史订单
     * @param ordersPageQueryDTO
     * @return
     */

    Page<Orders> page(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据id查询订单详情
     * @return
     */
    @Select("select *from orders where id=#{id}")
    Orders getOrders(Orders orders);


    /**
     * 各个订单状态的数量统计
     * @param deliveryInProgress
     * @return
     */
    @Select("select count(id) from orders where status=#{status}")
    Integer getStatistics(Integer deliveryInProgress);



    /**
     * 拒单
     * @param id
     * @return
     */
    @Select("select *from orders where id=#{id}")
    Orders getById(Long id);

    /**
     * 订单超时，取消支付
     * @param status
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getOrdersTimeoutTask(Integer status, LocalDateTime orderTime);

    /**
     * 报表营业额
     * @param map
     * @return
     */
    Double sum(HashMap<Object, Object> map);

    /**
     * 订单统计
     * @param map
     * @return
     */
    Integer getcountBy(HashMap<Object, Object> map);

    /**
     * 销量排名Top10
     * @param begintimes
     * @param endtimes
     * @return
     */
    List<GoodsSalesDTO> top10Report(LocalDateTime begintimes, LocalDateTime endtimes);


}

